package main

import (
	"context"
	"fmt"
	"time"

	"github.com/asim/go-micro/plugins/server/grpc/v4"
	"go-micro.dev/v4"

	"github.com/code-art/go-micro-mall/proto"
)

type Hello struct {
}

func (h Hello) Hello(ctx context.Context, request *proto.HelloRequest, response *proto.HelloResponse) error {
	fmt.Println("received: ", request.Name)
	response.Name = "response --> " + request.Name
	return nil
}

func main() {
	grpcServer := grpc.NewServer()
	rpcServer := micro.NewService(
		micro.RegisterTTL(time.Second*30),
		micro.RegisterInterval(time.Second*10),
		micro.Server(grpcServer),
		micro.Name("hello-service"),
		micro.Address(":8080"),
		micro.Version("latest"),
	)

	err := proto.RegisterHelloServiceHandler(rpcServer.Server(), &Hello{})
	if err != nil {
		return
	}
	if err := rpcServer.Run(); err != nil {
		fmt.Println(err)
	}
}
